<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <#include "../common/header.ftl">
</head>
<script>
    $(function () {
        $('#pagination').twbsPagination({
            totalPages:${result.pages},
            startPage:${result.pageNum},
            visiblePages:${result.pageSize},
            first:"首页",
            prev:"上一页",
            next:"下一页",
            last:"莫邪",

            onPageClick:function(event,page){
                $('#currentPage').val(page);
                $("#searchForm").submit();
            }
        });

        $(".addBtn").click(function () {
            $("#dictionaryId").val("")
            $("#sn").val("")
            $("#title").val("")
            $("#intro").val("")
            $("#myModal").modal('show')
        })

        $(".editBtn").click(function () {
            var data = $(this).data("jsonstr")
            $("#dictionaryId").val(data.id)
            $("#sn").val(data.sn)
            $("#title").val(data.title)
            $("#intro").val(data.intro)
            $("#myModal").modal('show')
        })
        
        $(".saveBtn").click(function () {
           $("#editForm").ajaxSubmit(function (data) {
               showMessager(data);
           })
        })


    })



    
</script>
<body>

<div class="container " style="margin-top: 20px">
<#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">字典管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/dictionary/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">

                <a  class="btn btn-success addBtn">添加</a>
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>名称</th>
                        <th>编码</th>
                        <th>简介</th>
                        <th>操作</th>
                    </tr>
                </thead>
                   <#list result.list as entity>
                   <tr>
                       <td>${entity_index}</td>
                       <td>${(entity.title)!}</td>
                       <td>${(entity.sn)!}</td>
                       <td>${(entity.intro)!}</td>
                       <td>
                           <@shiro.hasPermission name="dictionary:saveOrUpdate">
                               <a class="btn btn-info btn-xs editBtn" data-jsonstr='${(entity.jsonString)!}'>
                                   <span class="glyphicon glyphicon-pencil "></span>编辑
                               </a>
                           </@shiro.hasPermission>

                       </td>
                   </tr>
               </#list>
            </table>
            <div style="text-align: center;">
                <ul id="pagination" class="pagination"></ul>
            </div>
        </div>
    </div>
</div>

<div class="modal fade " tabindex="-1" id="myModal" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">字典编辑/保存</h4>
            </div>
                <div class="modal-body">
                    <form class="form-horizontal" action="/dictionary/saveOrUpdate.do" method="post" id="editForm">
                        <input type="hidden" id="dictionaryId" name="id">
                        <div class="form-group" >
                            <label for="title" class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="title" name="title" value="${(entity.title)!}" placeholder="请输入字典名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sn" class="col-sm-3 control-label">编码：</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="sn" name="sn" value="${(entity.sn)!}" placeholder="请输入字典编号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="intro" class="col-sm-3 control-label">简介：</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="intro" name="intro" value="${(entity.intro)!}" placeholder="请输入简介">
                            </div>
                        </div>
                    </form>
                </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary saveBtn" >确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


</body>
</html>